#coding:utf-8

import buss
from protocols import *

class HunterWirelessDownload(buss.BaseHunter):
    """
    columns : request, start, finish, downloadResult
    
    """
    name = u'无线下载'
    def init(self):

        #self.createTable(DOWNLOAD_SET, DOWNLOAD_RESPONSE, DOWNLOAD_FINISH, 
        #               DOWNLOAD_RESULT)
        self.data = {}
    
    def p_103d(self, data):
        p = Protocol103d(data)
        self.work.reportMessage(u"无线下载配置..")
        self.sendData(p)
 
    def p_107d(self, data):
        p = Protocol107d(data)
        if p.response == 0x01:
            self.work.reportMessage(u"车台应答无线下载配置成功..")
            self.work.reportMessage(u"车台开始执行无线下载..")
        else:
            self.work.reportMessage(u"车台应答无线下载配置失败..")
            self.endWork()

    def p_1089(self, data):
        p = Protocol1089(data)
        if p.response == 0x01:
            self.work.reportMessage(u"无线下载成功..")
        else:
            self.work.reportMessage(u"无线下载失败..")
        self.endWork()
        
        
        
class HunterVersionQuery(buss.BaseHunter):
    name = u"车台版本查询"
    def init(self):
        pass
    
    def p_1022(self, data):
        p = Protocol1022(data)
        self.work.reportMessage(u"车辆版本查询..")
        self.sendData(p)
        
    def p_1062(self, data):
        p = Protocol1062(data)
        self.work.reportMessage(u"版本查询应答:%s"%p.getVersion())
        